<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BTranslation
 *
 * @author I062261
 */
class BTTranslation extends BWEntity {

    //put your code here
    public $nativeSentence;
    public $foreignSentence;
    public $nativeLanguage = 'chinese';
    public $foreignLanguage = 'english';
    public $translationId = null;   

    public function save($nativeSentence = null, $foreignSentence = null, $nativeLanguage = NULL, $foreignLanguage = NULL) {
        if ($nativeLanguage == NULL)
            $nativeLanguage = $this->nativeLanguage;
        if ($foreignLanguage == NULL)
            $foreignLanguage = $this->foreignLanguage;
        if ($nativeSentence == NULL)
            $nativeSentence = $this->nativeSentence;
        if ($foreignSentence == NULL)
            $foreignSentence = $this->foreignSentence;

        $translateId = NULL;

        if ($nativeSentence != NULL && $foreignSentence != NULL) {
            if ($translateId == NULL) {
                $row = $this->getRepository()->getNewRow();
                $row->save();
                $translateId = $row->getId();
            }

            if ($translateId != NULL) {
                $nSentence = new BTSentence($nativeLanguage);
                $nSentence->sentence = $nativeSentence;
                $nSentence->translateId = $translateId;
                $nSentence->save();
                $this->nativeSentence = $nSentence;

                $fSentence = new BTSentence($foreignLanguage);
                $fSentence->sentence = $foreignSentence;
                $fSentence->translateId = $translateId;
                $fSentence->save();
                $this->foreignSentence = $fSentence;

                return $translateId;
            }
        }
    }
    
    public function getRepository($data = NULL) {
        $repository = parent::getRepository($data);
        $repository->setModel('BTMTranslation');
        return $repository;
    }

}

?>
